package com.dycx.user.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.*;

/**
 * @author 车辆能源类型
 * @date 2023/2/23
 */
@Getter
@AllArgsConstructor
public enum VehicleEnergyEnum {

    FUEL_OIL(1, "燃油"),
    ELECTRICITY(2, "电能");

    private final Integer code;
    private final String name;

    public static String converter(Integer code) {
        return Arrays.stream(values()).filter(en -> en.code.equals(code)).findAny().orElse(FUEL_OIL).getName();
    }

    /**
     * 转为数据
     *
     * @return 枚举对象数组
     */
    public static List<Map<String, Object>> getList() {
        List<Map<String, Object>> list = new ArrayList<>();
        for (VehicleEnergyEnum item : VehicleEnergyEnum.values()) {
            Map<String, Object> map = new HashMap<>();
            map.put("code", item.getCode());
            map.put("name", item.getName());
            list.add(map);
        }
        return list;
    }
}
